package com.hhsjdesign.dynamicui.asm.v3;

import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes

/**
 * 首先是类的访问
 */
class ASMClassVisitor extends ClassVisitor {

    ScanSettingV3 scanSettingV3
    ASMClassVisitor(ScanSettingV3 scanSettingV3, int api, ClassVisitor cv) {
        super(api, cv);
        this.scanSettingV3 = scanSettingV3
    }

    void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        super.visit(version, access, name, signature, superName, interfaces);
    }

    //访问方法，首先访问方法
    @Override
    MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions)
        //generate code into this method
        //访问我执行到方法。
        if (name == ScanSettingV3.GENERATE_TO_METHOD_NAME1
                || name == ScanSettingV3.GENERATE_TO_METHOD_NAME2
                || name == ScanSettingV3.GENERATE_TO_METHOD_NAME3
                || name == ScanSettingV3.GENERATE_TO_METHOD_NAME4
                || name == ScanSettingV3.GENERATE_TO_METHOD_NAME5
                || name == ScanSettingV3.GENERATE_TO_METHOD_NAME6
                || name == ScanSettingV3.GENERATE_TO_METHOD_NAME7
        ) {
//            mv = new DynamicUiMethodVisitor(scanSettingV3, Opcodes.ASM6, mv, name)

            mv = new InjectMethodVisitor(scanSettingV3, Opcodes.ASM6, mv, name)
        }
        return mv
    }
}